package com.educate.ucenter.shiro.realm;

import org.apache.shiro.authc.*;
import org.apache.shiro.authz.AuthorizationInfo;
import org.apache.shiro.realm.AuthorizingRealm;
import org.apache.shiro.subject.PrincipalCollection;

public class UserRealm extends AuthorizingRealm {

    @Override
    protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principalCollection) {
        return null;
    }

    @Override
    protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken authenticationToken) throws AuthenticationException {
        String username = (String) authenticationToken.getPrincipal();
        String password = new String((char[]) authenticationToken.getCredentials());
//        // 查询用户信息
//        UpmsUser upmsUser = upmsApiService.selectUpmsUserByUsername(username);
//
//        if (null == upmsUser) {
//            throw new UnknownAccountException();
//        }
//        if (!upmsUser.getPassword().equals(MD5Util.md5(password + upmsUser.getSalt()))) {
//            throw new IncorrectCredentialsException();
//        }
//        if (upmsUser.getLocked() == 1) {
//            throw new LockedAccountException();
//        }

        //密码比较
        return new SimpleAuthenticationInfo(username, password, getName());
    }
}
